// pages/zhaobiaoDetail/zhaobiaoDetail.js
var app = getApp();
var util = require("../../utils/util.js");
var config = require("../../utils/config.js");
var WxParse = require("../../wxParse/wxParse.js");
Page({
  /**
   * 页面的初始数据
   */
  data: {
    screen: app.data.screen,
    hidden: 2,
    message: {},
    lunbo: {},
    id: '',
    isDisabled: false,
    imglist: [
      '../../images/slider1.jpg',
      '../../images/slider2.jpg',
    ],
    indicatorDots: true,
    autoplay: true,
    interval: 5000,
    duration: 1000,
  },
  Tosignup(e){
    wx.navigateTo({
      url: "/pages/signUp/signUp?id=" + this.data.id
    })
    // console.log(e)
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad (options) {
    // console.log(options)
    this.setData({
      id: options.id,
    })
    var that = this;
    // 查看是否授权
    wx.getSetting({
      success(res) {
        console.log(res)
        if (res.authSetting['scope.userInfo']) {
          that.request(options.id);
        } else {
          wx.navigateTo({
            url: '/pages/login/login',
          });
        }
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  //  网络请求
  request(id) {
    util.getOpenID((e) => {
      var parameters = {
        openid: e.openid,
        id: id
      }
      util.postRequest(config.projectDetail, parameters, (res) => {
        console.log(res)
        if (res.code == 200) {
          var article = res.data.list.content
          WxParse.wxParse('article', 'html', article, this, 5);
          this.setData({
            hidden: 1,
            message: res.data.list,
            lunbo: res.data.lunbo,
          })
        } else if (res.code == 201) {
          wx.showToast({ title: '请求失败!', icon: 'none' })
        }
      }, () => {
        //请求失败
      }, () => {
        //请求完成
      }, true);
    }, true);
  }
})